package com.mybatis.core.service;

import com.mybatis.core.domain.User;
import com.mybatis.core.repository.UserRepository;
import com.mybatis.core.repository.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author xieshue
 * @date 2017\11\15 0015
 */
@Service
public class UserService {
    @Autowired
    private UserRepository userRepository;

    @Autowired
    private UserMapper userMapper;

    @Transactional(rollbackFor = Exception.class)
    public void save(List<User> users) {
        userRepository.save(users);
    }

    @Transactional(rollbackFor = Exception.class)
    public void insertBatch(List<User> users) {
        userRepository.save(users.get(0));
        userMapper.insertBatch(users);
    }

    public void insert(User user) {
        userMapper.insert(user);
    }
}
